export default {
  // 接口测试
  PORT_TEST({ commit }, payload) {
    const { url, method, timeout, parameter, pretreatmentCodeIds } = payload;
    return new Promise((resolve, reject) => {
      vm.$axios
        .post("/api/v1/datasource/testUrl", {
          url,
          method,
          timeout,
          parameter,
          pretreatmentCodeIds
        })
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 新增数据源
  ADD_DATA_SOURCE({ commit }, payload) {
    return new Promise((resolve, reject) => {
      vm.$axios
        .post("​/api​/v1​/datasource​/addDataSource", payload)
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 获取数据源
  GET_TABLE_SOURCE({ commit }, payload) {
    let { limit, page } = payload;
    return new Promise((resolve, reject) => {
      vm.$axios
        .get("/api/v1/datasource/listDataSource", {
          params: {
            pageSize: limit,
            pageNum: page
          }
        })
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 删除数据源
  REMOVE_DATA_SOURCE({ commit }, payload) {
    return new Promise((resolve, reject) => {
      vm.$axios
        .post("/api/v1/datasource/delDataSource/?id=" + payload)
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 编辑数据源
  EDIT_DATA_SOURCE({ commit }, payload) {
    return new Promise((resolve, reject) => {
      vm.$axios
        .post("/api/v1/datasource/editDataSource")
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 新增 列与结果值 映射
  ADD_RESULT_RELATIONSHIP({ commit }, payload) {
    return new Promise((resolve, reject) => {
      vm.$axios
        .post("/api/v1/dataengine/columnRelationship/add", {
          relationContent: JSON.stringify(payload)
        })
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 获取结果值映射
  GET_RESULT_RELATIONSHIP({ commit }, payload) {
    return new Promise((resolve, reject) => {
      vm.$axios
        .get("/api/v1/dataengine/columnRelationship/list")
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 新建数据表
  ADD_DATA_TABLE({ commit }, payload) {
    return new Promise((resolve, reject) => {
      vm.$axios
        .post("/api/v1/dataengine/dataTable/add", payload)
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 获取数据表
  GET_DATA_TABLELIST({ commit }, payload) {
    let { limit, page } = payload;
    return new Promise((resolve, reject) => {
      vm.$axios
        .get("/api/v1/dataengine/dataTable/list", {
          params: {
            pageSize: limit,
            pageNum: page
          }
        })
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 查询数据表（根据id）
  GET_BY_ID_TABLELIST({ commit }, payload) {
    return new Promise((resolve, reject) => {
      vm.$axios
        .get("/api/v1/dataengine/dataTable/getById", {
          params: {
            id: payload
          }
        })
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 删除数据表
  DELETE_DATA_TABLELIST({ commit }, payload) {
    return new Promise((resolve, reject) => {
      vm.$axios
        .post("/api/v1/dataengine/dataTable/del?id=" + payload)
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 获取脚本
  GET_SCRIPT({ commit }, payload) {
    return new Promise((resolve, reject) => {
      vm.$axios
        .get("/api/v1/pretreatmentCode/listCode")
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 获取所有java脚本模板
  GET_JAVA_CODETEMPLATE({ commit }, payload) {
    let { limit, page,type } = payload;
    return new Promise((resolve, reject) => {
      vm.$axios
        .get("/api/v1/dataengine/codeTemplate/list", {
          params: {
            type: type,
            pageSize: limit,
            pageNum: page
          }
        })
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
  // 删除java脚本模板
  DELETE_JAVA_CODETEMPLATE({ commit }, payload) {
    return new Promise((resolve, reject) => {
      vm.$axios
        .post("/api/v1/dataengine/codeTemplate/del?id=" + payload)
        .then((res) => {
          resolve(res);
        })
        .catch((err) => {
          reject(err);
        });
    });
  },
};
